package ift605.EquationWithTrainingAgents.agent;

import ift605.EquationWithTrainingAgents.behavior.reception.EmptyApplyDerivative;
import ift605.EquationWithTrainingAgents.behavior.reception.ReplaceDerivationPartBehavior;
import ift605.EquationWithTrainingAgents.behavior.reception.SumRebuildReceiveBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.AddBaseEquationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.AddOneBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.DiviseByLinearBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.MultiplyBaseEquationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.MultiplyCoefficientBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.NegateBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.NullMultiplicationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.RemoveOneBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.SubstractBaseEquationToDerivedBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.SubstractDerivedEquationToBaseBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.complex.DecreaseNumericPartEquationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.complex.MultNumericPartEquationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.complex.MultPartEquationBehavior;
import ift605.EquationWithTrainingAgents.behavior.special.complex.RequestDerivationBehavior;
import jade.core.Agent;
import jade.core.behaviours.Behaviour;
import jade.wrapper.AgentController;
import jade.wrapper.ContainerController;
import jade.wrapper.StaleProxyException;

public class PoolCreatorAgent extends Agent{
	private static final long serialVersionUID = 1L;

	public void setup(){
		try {
			ContainerController cc = this.getContainerController();

			createAgent("Negate", cc, new NegateBehavior(), new EmptyApplyDerivative());
			createAgent("DiviseByLinear", cc, new DiviseByLinearBehavior(), new EmptyApplyDerivative());
			createAgent("NullMultiplication", cc, new NullMultiplicationBehavior(), new EmptyApplyDerivative());
			createAgent("AddBaseEquation", cc, new AddBaseEquationBehavior(), new EmptyApplyDerivative());
			createAgent("SubstractBaseEquationToDerived", cc, new SubstractBaseEquationToDerivedBehavior(), new EmptyApplyDerivative());
			createAgent("SubstractDerivedEquationToBase", cc, new SubstractDerivedEquationToBaseBehavior(), new EmptyApplyDerivative()); // TODO remove this one, can be done otherwise
			createAgent("MultiplyBase", cc, new MultiplyBaseEquationBehavior(), new EmptyApplyDerivative());
			createAgent("Decrease numerics", cc, new DecreaseNumericPartEquationBehavior(), new EmptyApplyDerivative());
			createAgent("Mult numeric Part", cc, new MultNumericPartEquationBehavior(), new EmptyApplyDerivative());
			createAgent("Mult equation Part", cc, new MultPartEquationBehavior(), new EmptyApplyDerivative());
			
			createComplexAgent("Awesome",cc, new RequestDerivationBehavior(), new SumRebuildReceiveBehavior());

			//createAgent("AddOne", cc, new AddOneBehavior(), new EmptyApplyDerivative());
			//createAgent("RemoveOne", cc, new RemoveOneBehavior(), new EmptyApplyDerivative());
			//createAgent("MultiplyCoeff", cc, new MultiplyCoefficientBehavior(), new EmptyApplyDerivative());
			//createAgent("RequestDerivation", cc, new RequestDerivationBehavior(), new ReplaceDerivationPartBehavior());
			doDelete();
		
		} 
		catch (StaleProxyException e) {
			e.printStackTrace();
		}
	}
	
	protected void createAgent(String aName, ContainerController aContainer, Behaviour aMainBehavior, Behaviour aReceiveBehavior) throws StaleProxyException{
		String path = "ift605.EquationWithTrainingAgents.agent.PoolAgent";
		Object args[] = new Object[2];
		args[0]=aMainBehavior;
		args[1]=aReceiveBehavior;
		
		try {
			AgentController agent = aContainer.createNewAgent(aName, path, args);
			agent.start();
		} 
		catch (StaleProxyException e) {
			e.printStackTrace();
		}
	}
	
	protected void createComplexAgent(String aName, ContainerController aContainer, Behaviour aMainBehavior, Behaviour aReceiveBehavior) throws StaleProxyException{
		String path = "ift605.EquationWithTrainingAgents.agent.ComplexPoolAgent";
		Object args[] = new Object[2];
		args[0]=aMainBehavior;
		args[1]=aReceiveBehavior;
		
		try {
			AgentController agent = aContainer.createNewAgent(aName, path, args);
			agent.start();
		} 
		catch (StaleProxyException e) {
			e.printStackTrace();
		}
	}
}
